package com.example.lvsuo.controller.cxg;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.lvsuo.aop.Flow;
import com.example.lvsuo.aop.MoKuaiEnum;
import com.example.lvsuo.entity.cxg.vo.AdmArticlesVo;
import com.example.lvsuo.modal.Result;
import com.example.lvsuo.service.cxg.AdmArticlesService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 办公用品 controller
 */
@RestController
@RequestMapping("admarticles")
public class AdmArticlesController {

    @Autowired
    AdmArticlesService admArticlesService;

    @GetMapping
    public Result getAdmArticles(AdmArticlesVo admArticlesVo){
        /*
        奎哥式分页
        Page page = new Page();
        page.setCurrent(admArticlesVo.getPageCur());
        page.setSize(admArticlesVo.getPageSize());
        IPage<AdmArticlesVo> admArticlesVos = admArticlesService.getAdmArticles(page,admArticlesVo);
        */
        PageHelper.startPage(admArticlesVo.getPageCur(),admArticlesVo.getPageSize());

        PageInfo pageInfo = new PageInfo(admArticlesService.getAdmArticles(admArticlesVo));


//        IPage<AdmArticlesVo> admArticlesVos = admArticlesService.getAdmArticles(page,admArticlesVo);
        return Result.back("ok","20000",pageInfo);
    }

    @Flow(tName = "adm_articles",KUAI_ENUM = MoKuaiEnum.BGYP)
    @PostMapping
    public Result addAdmArticles(@RequestBody AdmArticlesVo admArticlesVo){
         admArticlesService.addAdmArticles(admArticlesVo);
        return Result.back("ok",20000) ;
    }

}
